import * as vite from "vite";
import { defineConfig as baseConfig, mergeConfig } from "vite";
import type {
  ConfigEnv,
  UserConfig,
  UserConfigFnObject,
  UserConfigExport,
  UserConfigFnPromise,
  UserConfigFn,
} from "vite";
import viteConfig from "./config";

export type {
  ConfigEnv,
  UserConfig,
  UserConfigFnObject,
  UserConfigExport,
  UserConfigFnPromise,
  UserConfigFn
};
export { mergeConfig, vite };
export function defineConfig(config: UserConfig): UserConfig
export function defineConfig(config: Promise<UserConfig>): Promise<UserConfig>
export function defineConfig(config: UserConfigFnObject): UserConfigFnObject
export function defineConfig(config: UserConfigFnPromise): UserConfigFnPromise
export function defineConfig(config: UserConfigFn): UserConfigFn
export function defineConfig(config: UserConfigExport): UserConfigExport
export function defineConfig(config: UserConfigExport): UserConfigExport {
  if (typeof config === 'function') {
    return baseConfig((params: ConfigEnv) => mergeConfig(viteConfig, config(params)))
  }
  return baseConfig(mergeConfig(viteConfig, config))
}
